package sjtu.sonnet.LDAPModule.logic.controller;

import java.util.Vector;

import sjtu.sonnet.LDAPModule.RBAC.model.group.iGroup;
import sjtu.sonnet.LDAPModule.RBAC.model.permission.iPermission;
import sjtu.sonnet.LDAPModule.RBAC.model.resource.AbstractResource;
import sjtu.sonnet.LDAPModule.RBAC.model.role.iRole;
import sjtu.sonnet.LDAPModule.RBAC.model.user.iUser;
import sjtu.sonnet.LDAPModule.logic.interfraces.RBACModelController;
import sjtu.sonnet.LDAPModule.service.exception.LDAPAddResourceException;
import sjtu.sonnet.LDAPModule.service.exception.LDAPAddRoleException;
import sjtu.sonnet.LDAPModule.service.exception.LDAPAddUserException;
import sjtu.sonnet.LDAPModule.service.exception.LDAPAddUserGroupException;
import sjtu.sonnet.LDAPModule.service.exception.LDAPDeleteRoleException;
import sjtu.sonnet.LDAPModule.service.exception.LDAPDeleteUserGroupException;
import sjtu.sonnet.LDAPModule.service.interfaces.LDAPService;

public class RBACModelControllerImpl implements RBACModelController {

	public RBACModelControllerImpl() {

	}

	public void addRole(iRole role) throws LDAPAddRoleException {
		this.ldapService.addRole(role);
	}

	public void addUserGroup(iGroup group) {

	}

	public iRole getRoleByName(String name) {
		return this.ldapService.getRoleByName(name);
	}

	public iGroup getUserGroupByName(String name) {
		return this.ldapService.getUserGroupByName(name);
	}

	public void setLdapService(LDAPService ldapService) {
		this.ldapService = ldapService;
	}

	public LDAPService getLdapService() {
		return ldapService;
	}

	public Vector<iRole> getAllRoles() {
		return this.ldapService.getAllRoles();
	}

	public Vector<iGroup> getAllGroup() {
		return this.ldapService.getAllGroups();
	}

	public Vector<AbstractResource> getAllResources() {
		return this.ldapService.getAllResources();
	}

	public Vector<iUser> getAllUsers(iGroup group) {
		return this.ldapService.getAllUsers(group);
	}

	private LDAPService ldapService = null;

	public void addUserGroup(iGroup group, iGroup parentGroup)
			throws LDAPAddUserGroupException {
		this.ldapService.addUserGroup(group, parentGroup.getName());
	}

	public Vector<iUser> getAllUsers() {
		// TODO Auto-generated method stub
		return null;
	}

	public void addUserGroup(iGroup group, String parentGroupName)
			throws LDAPAddUserGroupException {
		this.ldapService.addUserGroup(group, parentGroupName);
	}

	public void addUser(iUser user) throws LDAPAddUserException {
		this.ldapService.addUser(user);
	}

	public void deleteRole(String roleName) throws LDAPDeleteRoleException {
		this.ldapService.deleteRole(roleName);
	}

	public void deleteUserGroup(String groupName)
			throws LDAPDeleteUserGroupException {
		this.ldapService.deleteUserGroup(groupName);
	}

	public void addResource(AbstractResource resource)
			throws LDAPAddResourceException {
		this.ldapService.addResource(resource);
	}

	public void addPermissionToRole(iRole role, iPermission permission) {
		// TODO Auto-generated method stub
		role.addPermissions(permission);
		this.ldapService.updateRole(role);
	}

}
